package com.github.binarywang.demo.wx.cp.controller.smartTable;

import com.github.binarywang.demo.wx.cp.config.mutil.WxCpConfiguration;
import com.github.binarywang.demo.wx.cp.utils.JsonUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
public class SmartTableController {


    @PostMapping(value = "createDoc", produces = "application/xml; charset=UTF-8")
    public String post(@PathVariable String corpId,
                       @PathVariable Integer agentId,
                       @RequestBody String requestBody,
                       @RequestParam("msg_signature") String signature,
                       @RequestParam("timestamp") String timestamp,
                       @RequestParam("nonce") String nonce) {
//        log.info("\n接收微信请求：[signature=[{}], timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
//            signature, timestamp, nonce, requestBody);
//
//        final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId, agentId);
//        if (wxCpService == null) {
//            throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置，请核实！", agentId));
//        }
//
//        WxCpXmlMessage inMessage = WxCpXmlMessage.fromEncryptedXml(requestBody, wxCpService.getWxCpConfigStorage(),
//            timestamp, nonce, signature);
//        log.debug("\n消息解密后内容为：\n{} ", JsonUtils.toJson(inMessage));
//        WxCpXmlOutMessage outMessage = this.route(corpId, agentId, inMessage);
//        if (outMessage == null) {
//            return "";
//        }
//
//        String out = outMessage.toEncryptedXml(wxCpService.getWxCpConfigStorage());
//        log.debug("\n组装回复信息：{}", out);
//        return out;
        return null;
    }
}
